#include "user.h"
User::User(const int& id, const std::string& name, const std::string& password, const std::string& describe) :
    id(id), name(name), password(password), describe(describe) {
}

int User::getId()const { return this->id; } //获取用户的ID

std::string User::getName()const { return this->name; } //获取用户的名称


std::string User::getPassword()const { return this->password; } //获取用户的密码


std::string User::getDescribe()const { return this->describe; } //获取用户的描述


void User::setId(int id) { this->id = id; }//设置用户的ID

std::string User::serialize(void)const
{
    return std::to_string(this->id) + "|" + name + "|" + password + "|" + describe + "\n";
}

int User::deSerialize(const std::string& str)
{
    std::istringstream iss(str);
    std::string token;
    std::getline(iss, token, '|');
    id = std::stoi(token);
    std::getline(iss, token, '|');
    name = token;
    std::getline(iss, token, '|');
    password = token;
    std::getline(iss, describe);
    return 0;
}
